package gol;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Driver {
	static JFrame frame;
	
	public static void main(String[] args) {
	
		try {
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
					//Enforce java crossplatform LookAndFeel to prevent 
					//OSX Aqua ui elements using more space than expected.
		} catch (Exception e) {
			System.out.println("Failed to set LAF");
			e.printStackTrace();
		}
		
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {

				frame = new JFrame("Game of Life");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

				GameOfLife gol = new GameOfLife(frame);
				JScrollPane sp = new JScrollPane(gol);
				sp.getVerticalScrollBar().setUnitIncrement(6);
				sp.getHorizontalScrollBar().setUnitIncrement(6);
			//	sp.getViewport().setScrollMode(sp.getViewport().BLIT_SCROLL_MODE );//uhhh
				
				gol.addMouseMotionListener(new MouseMotionAdapter() {
					Rectangle r;
					public void mouseDragged(MouseEvent e) {
						r = new Rectangle(e.getX(), e.getY(), 1, 1);
						((GameOfLife) e.getSource()).scrollRectToVisible(r);
					}
				});

				gol.setAutoscrolls(true);
				frame.add(sp);

				GOLController golPanel = new GOLController(gol);
				frame.add(golPanel.getPanel(), BorderLayout.EAST);

				frame.setSize(590, 540);
				frame.setVisible(true);
			}
		});
	}
}
